<template>
  <div>
    <el-form :inline="true" :model="searchForm" class="demo-form-inline" >
      <el-form-item label="名称" >
        <el-input
          v-model="searchForm.brName"
          placeholder="输入店铺名称回车即可"
          @keydown.enter.native="getPage()"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="地址" >
        <el-input
          v-model="searchForm.brAddress"
          placeholder="输入地址回车即可"
          clearable
           @keydown.enter.native="getPage()"
        ></el-input>
      </el-form-item>

      <el-form-item>
         <el-button @click.native="reset()">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="brName" label="名称" width="180" />
      <el-table-column prop="brAddress" label="地址" width="180" />
      <el-table-column prop="closeDate" label="关店时间" />
    </el-table>

    <el-pagination
      :page-size="limit"
      :current-page="page"
      :page-sizes="[2, 10, 20, 30]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />

  </div>
</template>
<script>
export default {
  data() {
    return {
      searchForm: {},
      tableData: [],
      page: 1,
      limit: 10,
      total: 0,
      title: "添加分店",
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      value1: "",
      value2: "",
      value3: "",
    };
  },
  created() {
    this.getPage();
  },
  computed: {},
  watch: {
    searchForm: {
      deep: true,
      handler(val) {
       if(val.brName==''){
         val.brName=null
       }
       if(val.brAddress==''){
         val.brAddress=null
       }
      },
    },
  },
  methods: {
    reset(){
      this.searchForm={}
      this.getPage();
    },
   
    getPage() {
      this.$http
        .post(
          `http://127.0.0.1/branch/pageHistory/${this.page}/${this.limit}`,
          this.searchForm
        )
        .then(({ data }) => {
          this.tableData = data.pageInfo.list;
          this.total = data.pageInfo.total;
        });
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getPage();
    },
    handleSizeChange(val) {
      this.limit = val;
      this.getPage();
    },
    
  },
};
</script>
<style  scoped>
</style>